﻿using System.Windows.Forms;
using DevExpress.XtraEditors.DXErrorProvider;
using WinUtilities.Class;

namespace VCS.Windows.Forms.Form.Main
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FormMedicalProcedure : DevExpress.XtraEditors.XtraForm
    {
        /// <summary>
        /// 
        /// </summary>
        public string Description;

        /// <summary>
        /// 
        /// </summary>
        public decimal Price;
        /// <summary>
        /// 
        /// </summary>
        public FormMedicalProcedure()
        {
            InitializeComponent();
            calc_Price.Value = 0;
            ValidateField();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="description"></param>
        /// <param name="price"></param>
        public FormMedicalProcedure(string description, decimal price)
        {
            InitializeComponent();
            txt_Description.Text = description;
            calc_Price.Value = price;
            ValidateField();
        }
        private void ValidateField()
        {
            if (string.IsNullOrEmpty(txt_Description.Text))
                dxErrorProvider1.SetError(txt_Description, txt_Description.ToolTip, ErrorType.Critical);
            else
                dxErrorProvider1.SetError(txt_Description, "");
            if (calc_Price.Value < 0)
                dxErrorProvider1.SetError(calc_Price, calc_Price.ToolTip, ErrorType.Critical);
            else
                dxErrorProvider1.SetError(calc_Price, "");

        }

        protected override void OnVisibleChanged(System.EventArgs e)
        {
            if (Visible)
            {
                ValidateField();
            }
            base.OnVisibleChanged(e);
        }
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (GlobalUtilities.GlobalProcessCmdKey(this, FormHotKey, ref msg, keyData))
                return true;
            return base.ProcessCmdKey(ref msg, keyData);
        }
        private bool FormHotKey(Keys keys)
        {
            return false;
        }

        private void btn_AddProcedure_Click(object sender, System.EventArgs e)
        {
            if (!dxErrorProvider1.HasErrors)
            {
                Description = txt_Description.Text;
                Price = calc_Price.Value;
                Close();
            }
        }

        private void txt_Description_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(txt_Description.Text))
                dxErrorProvider1.SetError(txt_Description, txt_Description.ToolTip, ErrorType.Critical);
            else
                dxErrorProvider1.SetError(txt_Description, "");
        }
    }
}